/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            adminWorkPoolInfo: {
                works: [],
                states: [
                    {
                        name: '全部',
                        state: ''
                    }, {
                        name: '待处理',
                        state: 'W'
                    }, {
                        name: '处理完成',
                        state: 'C'
                    }, {
                        name: '超时工作单',
                        state: 'timeout'
                    }
                ],
                total: 0,
                records: 1,
                moreCondition: false,
                wtId: '',
                conditions: {
                    state: '',
                    typeName: '',
                    staffNameLike: '',
                    workNameLike: '',
                    queryEndTime: '',
                    queryStartTime: '',
                    createUserNameLike: '',
                    communityId:'',
                }
            }
        },
        _initMethod: function () {
            $that._listAdminWorkPools(DEFAULT_PAGE, DEFAULT_ROWS);
        },
        _initEvent: function () {
            vc.on('selectAdminCommunity','changeCommunity',function(_community){
                $that.adminWorkPoolInfo.conditions.communityId = _community.communityId;
                $that._listAdminWorkPools(DEFAULT_PAGE, DEFAULT_ROWS);
            })
            vc.on('adminWorkPool', 'listAdminWorkPool', function (_param) {
                $that._listAdminWorkPools(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listAdminWorkPools(_currentPage, DEFAULT_ROWS);
            });
            vc.initDateTime('queryStartTime', function (_value) {
                $that.adminWorkPoolInfo.conditions.queryStartTime = _value;
            })
            vc.initDateTime('queryEndTime', function (_value) {
                $that.adminWorkPoolInfo.conditions.queryEndTime = _value;
            })
        },
        methods: {
            _listAdminWorkPools: function (_page, _rows) {
                $that.adminWorkPoolInfo.conditions.page = _page;
                $that.adminWorkPoolInfo.conditions.row = _rows;
                let param = {
                    params: JSON.parse(JSON.stringify($that.adminWorkPoolInfo.conditions))
                };
                if (param.params.state == 'timeout') {
                    param.params.state = 'C';
                    param.params.taskTimeout = 'Y'
                }
                //发送get请求
                vc.http.apiGet('/work.listAdminWorkTask',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.adminWorkPoolInfo.total = _json.total;
                        $that.adminWorkPoolInfo.records = _json.records;
                        $that.adminWorkPoolInfo.works = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.adminWorkPoolInfo.records,
                            dataCount: $that.adminWorkPoolInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _toWorkDetailPage: function (_work) {
                vc.jumpToPage('/#/pages/oa/adminWorkDetail?workId=' + _work.workId);
            },
            _queryAdminWorkPoolMethod: function () {
                $that._listAdminWorkPools(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _resetAdminWorkPoolMethod: function () {
                vc.component.adminWorkPoolInfo.conditions.workNameLike = "";
                vc.component.adminWorkPoolInfo.conditions.createUserNameLike = "";
                vc.component.adminWorkPoolInfo.conditions.staffNameLike = "";
                vc.component.adminWorkPoolInfo.conditions.queryStartTime = "";
                vc.component.adminWorkPoolInfo.conditions.queryEndTime = "";
                $that._listAdminWorkPools(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            swatchWorkState: function (_state) {
                $that.adminWorkPoolInfo.conditions.state = _state.state;
                $that._listAdminWorkPools(DEFAULT_PAGE, DEFAULT_ROWS);
            }
        }
    });
})(window.vc);
